package com.tanjun.userservice.web.controller.admin;

import com.tanjun.common.annotation.Edit;
import com.tanjun.common.annotation.Insert;
import com.tanjun.common.model.R;
import com.tanjun.common.response.PageResponse;
import com.tanjun.userservice.apiservice.request.adminuser.AdminResetPasswordRequest;
import com.tanjun.userservice.apiservice.request.adminuser.AdminUserIdListRequest;
import com.tanjun.userservice.apiservice.request.adminuser.AdminUserPageRequestRequest;
import com.tanjun.userservice.apiservice.request.adminuser.AdminUserRequest;
import com.tanjun.userservice.apiservice.response.adminuser.admin.AdminUserDetailResponse;
import com.tanjun.userservice.web.biz.admin.AdminUserBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.tanjun.common.constants.UrlConstant.URL_USER.ADMIN;
import static com.tanjun.common.constants.UrlConstant.URL_AUTH.AUTH;

@RestController
@RequestMapping(ADMIN+"/adminUser")
@Slf4j
public class BaseAdminUserController{
    @Autowired
    private AdminUserBiz adminUserBiz;


    /**
     * 新增管理用户
     * @param paramVo 用户信息
     * @return R
     */
    @PostMapping(AUTH+"/add")
    public R addAdminUser(@RequestBody @Validated(Insert.class) AdminUserRequest paramVo){
        adminUserBiz.addAdminUser(paramVo);
        return R.OK();
    }

    /**
     * 修改管理用户
     * @param paramVo 用户信息
     * @return R
     */
    @PostMapping(AUTH+"/update")
    public R updateAdminUser(@RequestBody @Validated(Edit.class) AdminUserRequest paramVo){
        adminUserBiz.updateAdminUser(paramVo);
        return R.OK();
    }

    /**
     * 分页查询用户信息
     * @param paramVo 请求参数
     * @return 返回结果
     */
    @PostMapping(AUTH+"/listPage")
    public R<PageResponse<AdminUserDetailResponse>> listPage(@RequestBody @Validated AdminUserPageRequestRequest paramVo){
        return R.OK(adminUserBiz.listPage(paramVo));
    }

    /**
     * 根据用户id获取用户信息
     * @param userId 用户id
     * @return 用户信息
     */
    @GetMapping(AUTH+"/getById")
    public R<AdminUserDetailResponse> getById(@RequestParam("userId") Long userId){
        return R.OK(adminUserBiz.getByUsrId(userId));
    }

    /**
     * 重置密码
     * @param paramVo 重置密码
     * @return R
     */
    @PostMapping(AUTH+"/resetPassword")
    public R resetPassword(@RequestBody @Validated AdminResetPasswordRequest paramVo){
        adminUserBiz.resetPassword(paramVo);
        return R.OK();
    }

    /**
     * 重置密码
     * @param paramVo 重置密码
     * @return R
     */
    @PostMapping(AUTH+"/deleteByIds")
    public R deleteByIds(@RequestBody @Validated AdminUserIdListRequest paramVo){
        adminUserBiz.delAdminUser(paramVo);
        return R.OK();
    }

}
